package com.chuangke.system.util;

import java.util.Date;

import com.chuangke.admin.entity.SysUser;
import com.chuangke.admin.service.SysUserService;
import com.chuangke.common.utils.HttpServletRequestUtils;
import com.chuangke.common.utils.HttpUtils;
import com.chuangke.common.utils.SecurityUtils;
import com.chuangke.common.utils.SpringContextUtil;
import com.chuangke.system.entity.SysOptLog;

public class OptLogUtil {

	public static void setDefaultValues(SysOptLog log) {
		SysUserService sysUserService = SpringContextUtil.getBean(SysUserService.class) ;
		String userName = SecurityUtils.getUserId();
		SysUser user = sysUserService.findById(userName) ;
		
		log.setDeptId(user== null ? "":user.getDeptId());
    	log.setUserId(userName);
    	log.setUserName(user== null ? "":user.getNickName());
    	log.setCreateTime(new Date());
    	log.setIpaddr(HttpServletRequestUtils.getIpAddr(HttpUtils.getHttpServletRequest())) ;
    	log.setOs(HttpServletRequestUtils.getOs(HttpUtils.getHttpServletRequest()));
    	log.setBrowser(HttpServletRequestUtils.getBrowser(HttpUtils.getHttpServletRequest()));
	}
}
